package databasex

import (
	"context"
	_ "embed"
	"sync"

	"github.com/pelletier/go-toml/v2"
)

var Ctx = context.Background()

type Server struct {
	Host     string `yaml:"host" json:"host" toml:"host"`             //测试host
	Database string `yaml:"database" json:"database" toml:"database"` //链接目标数据库
}

//go:embed config.toml
var configData []byte

var ServerConfig Server
var once sync.Once

func init() {
	once.Do(func() {
		err := toml.Unmarshal(configData, &ServerConfig)
		if err != nil {
			panic(err)
		}

		if len(ServerConfig.Database) == 0 {
			ServerConfig.Database = "test"
		}

		if len(ServerConfig.Host) == 0 {
			ServerConfig.Host = host
		}
	})
}

var host = "192.168.11.5"
